package com.openningbook;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.border.LineBorder;
import javax.swing.tree.DefaultTreeCellRenderer;

public class MyTreeCellRenderer extends DefaultTreeCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5228519386488530017L;

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
			int row, boolean hasFocus) {
		String str = value.toString();
		JLabel jl = new JLabel(str);
		jl.setBorder(new LineBorder(tree.getBackground()));
		if (sel) {
			jl.setBorder(new LineBorder(Color.blue));
		}
		if (row == 0) {
			jl.setForeground(Color.gray);
		} else if (str.charAt(3) >= '0' && str.charAt(3) <= '9') {
			jl.setForeground(Color.black);
		} else {
			jl.setForeground(Color.red);
		}
		return jl;
	}

}
